Skip to content

fix(engine): a nested command's "changed nothing" flag no longer reaches the command that ran it (#2637) - #2834

Open
choupeanut wants to merge 2 commits into
opengeos:mainfrom
choupeanut:fix/2637-request-only-scope
Open

choupeanut wants to merge 2 commits into
opengeos:mainfrom
choupeanut:fix/2637-request-only-scope

Conversation

@choupeanut

@choupeanut choupeanut commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Session::request_only ("this command only left a request, or changed nothing: no undo step") is one flag for the whole session. guarded_inner cleared it when a command started and read it only in the branch for commands that mutate, so a nested command that did not mutate, or that set it and then failed, left it set. The command that ran it then read that as its own and took no undo step for its own edit. No command known on main does this today; run_part (the GeoLibre and QGIS imports), model.import and any command that runs another can.

  • guarded_inner (crates/engine/src/lib.rs) now saves the enclosing command's flag when a command starts and puts it back when it ends, as shared_step already does for a script line. Both reads of the flag happen before the restore, so a command still decides its own step. There is no ? or early return between the save and the restore, and a panic in the command is caught into an error first, so the restore runs on every path.
  • Not built: the issue's explicit account of what nested commands did (as shared_steps does for shared steps). Nothing would read it: a nested command takes its own undo step or none, and the command that ran it does not follow it. A command that wants to follow its tools (the model) already counts them itself.
  • model.rs: a model sets its own flag from what its tools did (file_pending && !tool_completed), where it cleared a flag its tools had left.
  • cmd/geolibre.rs: the line that sets the flag to false stays, with a comment saying why. The import calls request_import_url itself, which sets the flag in the import's own scope. That is not a nested-command leak, so the guard change does not cover it: with the line removed, an import that leaves a download took no undo step (0 steps, expected 1). A new test pins it.
  • One small behaviour change: a failed atomic step (a savepoint) no longer adds to shared_steps.requested, because restore_url_request_checkpoint withdraws its request and its flag no longer outlives it. Before, a plugin command whose only request failed could end up with no undo step.
  • cmd/plugins.rs: comments only. A plugin command that may edit keeps its undo step even when it changed nothing, and two existing tests pin that (plugin_settings_are_kept_per_plugin_across_sessions_updates_and_toggles, shape_conversion_plugin_handled_rejection_is_atomic_and_has_no_inner_undo); a script or task takes none in that case. The issue allowed writing the reason next to the rule instead of unifying, so that is what this does. Unifying would change the Undo list for plugin commands, a rule change for the maintainer.

Testing

  • New a_nested_commands_request_flag_is_not_the_enclosing_commands: a mutating command that runs a non-mutating nested command which leaves a request, or a nested one that sets the flag and fails, and then edits, records one undo step and Undo takes the edit back; a command that sets the flag itself still records none. Fails on the old code (the outer edit takes its step, left 0, right 1), passes now.
  • New a_nested_panic_leaves_the_enclosing_commands_request_flag_alone: a nested command sets the flag and panics; the panic becomes its error, and the enclosing command that goes on keeps its step.
  • New a_script_that_leaves_a_request_and_then_edits_is_one_undo_step: through script.run with no network (layer.addUrl held for the app): request then edit is one step, a request alone none. The script's lines were already isolated by shared_step; this pins it.
  • New geolibre_import_that_leaves_a_download_is_one_undo_step: passes before and after; it fails if the kept line in cmd/geolibre.rs is removed.
  • Existing model tests cover "a model that only queued bytes has no step" (file_only_model_still_skips_an_empty_undo_step_and_completes_on_delivery) and "a queued file beside a completed tool keeps the step" (queued_file_does_not_hide_undo_for_prior_model_tools); they pass.
  • cargo test -p rustgis-engine and cargo clippy -p rustgis-engine --all-targets -- -D warnings: pass (engine lib 2257 passed, 0 failed, 9 ignored; engine integration 214 passed, 0 failed, 2 ignored; clippy clean).
  • Local gate on origin/main (463133b) with this branch and my other branch fix/2758-inline-graph-capabilities merged, in an English locale: pre-commit on every file, cargo fmt --check, clippy with -D warnings, cargo xtask layers, cargo xtask schema --check with the fixtures and test hygiene, cargo xtask rows, and the Python package's tests (maturin + pytest, 49 passed) pass. cargo test --workspace: 9313 passed, 3 failed. The 3 compare memory limits read at two moments while free memory moved under the gate's load (oversized_geojson_publish_gives_vector_advice, oversized_shapefile_dbf_read_for_publish_gives_dataset_advice, analysis_workflows_models_scripts_and_raster_functions), and each passes when run alone. Not run here: the wasm32 build (no clang on this machine; CI's Web app job checks it), macOS and Windows.

Reach every surface

Engine only, so every surface that runs commands gets it: desktop, browser, command line, Python, the phone, the Assistant, MCP and plugins. No command, parameter, notice, saved-file or interface text changes, so the ribbon, the Assistant's tool descriptions, the command-surface snapshot and the translation catalogs are unchanged. Undo and Redo behave as before; the change only stops a command that edited from losing its step. Nothing drops or approximates data, so there is no notice to add. Nothing is behind cfg, so the browser build is unchanged.

UI evidence

No visible UI change.

Related issue

Closes #2637

Summary by CodeRabbit

  • Bug Fixes
    • Undo history is now preserved correctly when commands run within other commands, including when a nested command leaves a download request or encounters an error.
    • Imports that leave a download request now retain an undo step, and scripts that both request a download and make edits remain undoable.
    • Commands that only request a download without making edits continue to leave no undo step.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change scopes request_only to guarded commands by restoring the enclosing value after each command. It also updates run_into’s assignment and adds tests for undo behavior in nested commands, scripts, and GeoLibre imports.

Changes: Undo-step accounting

Layer / File(s) Summary
Scope request-only state to guarded commands
crates/engine/src/lib.rs, crates/engine/src/tests.rs
Guarded commands save and restore the enclosing request_only value. Tests cover nested requests, failures, panics, and script edits.
Handle request-only outcomes
crates/engine/src/model.rs, crates/engine/src/cmd/plugins.rs, crates/engine/src/cmd/geolibre.rs, crates/engine/src/tests.rs
run_into assigns request_only from pending-file and completed-tool state. Comments describe plugin and GeoLibre undo-step rules. A test covers a GeoLibre import that leaves a download request.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related PRs

  • opengeos/RustGIS#2622: Changes undo accounting for scripts, tasks, and plugin calls, which overlaps with this PR’s request-only and undo-step accounting.

Suggested reviewers: deniial00, jgregoriorincon, giswqs

Merge Risk: Minimal · up to 4b12a

The change scopes the request-only undo flag to the command that set it, so a nested request can no longer suppress an enclosing command's undo step. Targeted tests cover the new behavior. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a nested command's "changed nothing" flag (request_only) no longer reaches the enclosing command. The raw summary and objectives confirm guarded_inner now saves and re…
Description check Passed The description follows the template: it has a Summary, a Testing section with commands and new tests, a UI evidence section stating no visible UI change, and a Related issue that closes #2637. It exp…
Linked Issues check Passed [#2637] The core defect is addressed. The PR description and summary state that guarded_inner in crates/engine/src/lib.rs now saves the enclosing request_only value at command start and restores…
Out of Scope Changes check Passed Changes map to the linked issue or follow from it. crates/engine/src/lib.rs: the save and restore of request_only in guarded_inner is the core fix. crates/engine/src/model.rs: the flag assignm…
Full details: Title check

Explanation

The title names the main change: a nested command's "changed nothing" flag (request_only) no longer reaches the enclosing command. The raw summary and objectives confirm guarded_inner now saves and restores request_only, which matches the title. It is specific and single-sentence, though at 104 characters it is somewhat long.

Full details: Description check

Explanation

The description follows the template: it has a Summary, a Testing section with commands and new tests, a UI evidence section stating no visible UI change, and a Related issue that closes #2637. It explains the cause, the fix, the GeoLibre line kept, the plugin comments, and a small behaviour change. The template's UI section is filled in correctly.

Full details: Linked Issues check

Explanation

[#2637] The core defect is addressed. The PR description and summary state that guarded_inner in crates/engine/src/lib.rs now saves the enclosing request_only value at command start and restores it at command end. Both reads of the flag occur before the restore, and no ? or early return sits between save and restore. Panics are caught into errors first. New tests cover: a mutating command running a non-mutating nested command that leaves a request, then editing (one undo step); a nested command that sets the flag and fails; a nested panic; and a script that leaves a request and then edits (one step). The issue's model case (queued bytes only, no step) is covered by existing tests file_only_model_still_skips_an_empty_undo_step_and_completes_on_delivery and queued_file_does_not_hide_undo_for_prior_model_tools. In crates/engine/src/model.rs, the diff confirms the manual clear is replaced by s.request_only = file_pending && !tool_completed;, which matches the issue's request to remove the manual clear. Plugin handling follows the issue's allowed alternative: the reason is written as comments next to the rule in cmd/plugins.rs. Two requirements are not implemented as the issue describes. (1) The issue's expected behavior asks for an explicit account of nested-command effects, as shared_steps provides. The PR declines this with a stated reason: no reader exists, because a nested command takes its own step and the enclosing command does not follow it. (2) The issue asks that the manual clear in cmd/geolibre.rs go away. The PR keeps it, with a comment. It also adds a test that fails without the line (0 steps, expected 1), which shows the import's flag is set in its own scope and not by a nested command. These two deviations are explained with evidence. Limit: the crates/engine/src/lib.rs diff could not be read, because changed blobs were missing from the checkout. The lib.rs behavior rests on the PR summary and description, not on a direct code read.

Full details: Out of Scope Changes check

Explanation

Changes map to the linked issue or follow from it. crates/engine/src/lib.rs: the save and restore of request_only in guarded_inner is the core fix. crates/engine/src/model.rs: the flag assignment replaces a manual clear that the issue names for removal. crates/engine/src/cmd/geolibre.rs: a comment-only change explaining a retained line; no executable change. crates/engine/src/cmd/plugins.rs: comments only, documenting the plugin rule the issue permits. crates/engine/src/tests.rs: tests for the described behavior. The behavior change to shared_steps.requested (a failed atomic step no longer adds to it) follows from the flag no longer outliving the withdrawn request in restore_url_request_checkpoint. The PR describes this change and its effect on plugin commands. It is a direct consequence of the fix, not an unrelated change. No unrelated feature, UI, parameter, or data change appears in the description or summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the undo stack,
Nested requests no longer sneak back.
One command keeps its own state,
Edits can undo and set things straight.
A download waits, then hops away.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8b4c2491-e8c1-41fe-9be4-a8a6661b2ccc
Commits

Reviewing files that changed from the base of the PR and between 9bb44c8 and 4b12a7a.

Files selected for processing: 5

  • crates/engine/src/cmd/geolibre.rs
  • crates/engine/src/cmd/plugins.rs
  • crates/engine/src/lib.rs
  • crates/engine/src/model.rs
  • crates/engine/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread crates/engine/src/lib.rs
let counts = mutates.then(|| self.edit_counts.clone());
self.request_only = false;
// Its flag is its own: the enclosing command's comes back after it, whatever it left.
let outer_request_only = std::mem::take(&mut self.request_only);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible regression, low confidence (about 30%), not reproduced.

Before this change, a non-mutating nested command's "left a request" flag leaked up to whatever step ran it. shared_step reads that flag as unchanged and feeds shared_steps.requested and edited. Now guarded_inner restores the enclosing flag on exit, so a Shared step (Txn::Shared in dispatch.rs) whose handler runs a non-mutating nested command that only left a download will see unchanged == false. If the step is declared mutates, edited becomes true, and the script or plugin then takes an empty undo step, where it previously took none.

The PR description says "Nothing would read it", but shared_step (lib.rs ~2316) does read the signal. I did not find a shipped handler that combines a non-mutating nested request with a mutating step, so the impact may be hypothetical. A test would settle it: a Registered mutating command whose handler calls s.guarded("x", false, |s| s.request_url(..)) and makes no edits, run as a script line. Expected result: no undo step. If that case is intended to stay "no step", the isolation needs to carry the nested signal up to shared_steps.requested rather than dropping it.

Category: bug

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • crates/engine/src/lib.rs:2362: a non-mutating nested command's "left a request" signal no longer reaches a Shared step (script or plugin line) that delegates to it. If that step is declared mutates, it can now take an empty undo step. Confidence is low, about 30%, and I did not reproduce it. The PR says nothing reads the signal, but shared_step does. Posted inline.

Security

  • None found.

Performance

  • None found.

Quality

  • crates/engine/src/cmd/plugins.rs:946-952: the new comment is long, explains the mechanism, and names three tests. Shorten it to the rule. Left for the release quality pass.
  • crates/engine/src/lib.rs (guarded_inner, the restore after the match): the PR says the flag is restored on every path, because a panic is caught into an error first. That holds for the command body. Panics in the bookkeeping after it (roughly lines 2378–2518) skip the restore. Confidence is high that this is true, and low that it matters, since those paths should not panic.

AGENTS.md

  • None found. The new tests use unwrap and panic! only in test code. No command, parameter, saved file, or interface text changes, so the surface snapshot and schema are unaffected.

Checked and found correct

  • The save and restore of request_only in guarded_inner brackets the command with no early return, and the Ok and Err arms read the flag before the restore.
  • The model.rs assignment is deterministic now: file_pending && !tool_completed.
  • The plugins.rs assignments sit inside their guarded closures, so the restore reads them correctly.
  • The shared_step change for failed atomic steps is right, since the restore withdraws the flag.
  • The test names cited in the comments exist.

I left no earlier threads alone, since prior-reviews.json had none.

Change size

Compared with the base branch: the whole PR, merge base dd3d011 to head 4b12a7a. Files changed: 5 (0 added, 5 modified, 0 removed, 0 renamed).

Measure Value
Files changed 5 (0 added, 5 modified, 0 removed, 0 renamed)
Size before 3,896.9 KB (3.81 MB)
Size after 3,902.2 KB (3.81 MB)
Total size change +5.2 KB

Sizes are in binary KB and MB (1 KB = 1024 B).

File Before After Change
crates/engine/src/tests.rs 3,519.1 KB 3,523.3 KB +4.2 KB
crates/engine/src/cmd/plugins.rs 73.8 KB 74.4 KB +615 B
crates/engine/src/lib.rs 203.2 KB 203.6 KB +310 B
crates/engine/src/cmd/geolibre.rs 34.5 KB 34.6 KB +164 B
crates/engine/src/model.rs 66.4 KB 66.3 KB −24 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Commit 4b12a7a from a fork built, but isn't published until a maintainer adds the preview label (once per commit).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

request_only set by a nested command leaks into the command that ran it

1 participant